{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "265da951",
   "metadata": {},
   "source": [
    "# 入门训练"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a2ab519f",
   "metadata": {},
   "source": [
    "### 试题 入门训练 Fibonacci数列"
   ]
  },
  {
   "cell_type": "raw",
   "id": "48af1a7b",
   "metadata": {},
   "source": [
    "资源限制\n",
    "时间限制：1.0s   内存限制：256.0MB\n",
    "问题描述\n",
    "Fibonacci数列的递推公式为：Fn=Fn-1+Fn-2，其中F1=F2=1。\n",
    "\n",
    "当n比较大时，Fn也非常大，现在我们想知道，Fn除以10007的余数是多少。\n",
    "\n",
    "输入格式\n",
    "输入包含一个整数n。\n",
    "输出格式\n",
    "输出一行，包含一个整数，表示Fn除以10007的余数。\n",
    "说明：在本题中，答案是要求Fn除以10007的余数，因此我们只要能算出这个余数即可，而不需要先计算出Fn的准确值，再将计算的结果除以10007取余数，直接计算余数往往比先算出原数再取余简单。\n",
    "\n",
    "样例输入\n",
    "10\n",
    "样例输出\n",
    "55\n",
    "样例输入\n",
    "22\n",
    "样例输出\n",
    "7704\n",
    "数据规模与约定\n",
    "1 <= n <= 1,000,000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "66386096",
   "metadata": {},
   "outputs": [],
   "source": [
    "n=int(input())\n",
    "f1=f2=f3=1\n",
    "if n == 1 or n == 2:\n",
    "    print(1)\n",
    "elif n > 2:\n",
    "    for i in range(3,n+1):\n",
    "        f3 = (f1 + f2) % 10007\n",
    "        f1 = f2\n",
    "        f2 = f3\n",
    "    print(f3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79983f71",
   "metadata": {},
   "source": [
    "### 试题 入门训练 圆的面积"
   ]
  },
  {
   "cell_type": "raw",
   "id": "fc9ed016",
   "metadata": {},
   "source": [
    "资源限制\n",
    "时间限制：1.0s   内存限制：256.0MB\n",
    "问题描述\n",
    "给定圆的半径r，求圆的面积。\n",
    "输入格式\n",
    "输入包含一个整数r，表示圆的半径。\n",
    "输出格式\n",
    "输出一行，包含一个实数，四舍五入保留小数点后7位，表示圆的面积。\n",
    "说明：在本题中，输入是一个整数，但是输出是一个实数。\n",
    "\n",
    "对于实数输出的问题，请一定看清楚实数输出的要求，比如本题中要求保留小数点后7位，则你的程序必须严格的输出7位小数，输出过多或者过少的小数位数都是不行的，都会被认为错误。\n",
    "\n",
    "实数输出的问题如果没有特别说明，舍入都是按四舍五入进行。\n",
    "\n",
    "样例输入\n",
    "4\n",
    "样例输出\n",
    "50.2654825\n",
    "数据规模与约定\n",
    "1 <= r <= 10000。\n",
    "提示\n",
    "本题对精度要求较高，请注意π的值应该取较精确的值。你可以使用常量来表示π，比如PI=3.14159265358979323，也可以使用数学公式来求π，比如PI=atan(1.0)*4。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2bab4c54",
   "metadata": {},
   "outputs": [],
   "source": [
    "r = int(input())\n",
    "PI = 3.1415926535\n",
    "area = pow(r,2) * PI\n",
    "print(round(area, 7))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c844f40f",
   "metadata": {},
   "source": [
    "### 试题 入门训练 序列求和"
   ]
  },
  {
   "cell_type": "raw",
   "id": "0ed39ff2",
   "metadata": {},
   "source": [
    "资源限制\n",
    "时间限制：1.0s   内存限制：256.0MB\n",
    "问题描述\n",
    "求1+2+3+...+n的值。\n",
    "输入格式\n",
    "输入包括一个整数n。\n",
    "输出格式\n",
    "输出一行，包括一个整数，表示1+2+3+...+n的值。\n",
    "样例输入\n",
    "4\n",
    "样例输出\n",
    "10\n",
    "样例输入\n",
    "100\n",
    "说明：有一些试题会给出多组样例输入输出以帮助你更好的做题。\n",
    "\n",
    "一般在提交之前所有这些样例都需要测试通过才行，但这不代表这几组样例数据都正确了你的程序就是完全正确的，潜在的错误可能仍然导致你的得分较低。\n",
    "\n",
    "样例输出\n",
    "5050\n",
    "数据规模与约定\n",
    "1 <= n <= 1,000,000,000。\n",
    "说明：请注意这里的数据规模。\n",
    "\n",
    "本题直接的想法是直接使用一个循环来累加，然而，当数据规模很大时，这种“暴力”的方法往往会导致超时。此时你需要想想其他方法。你可以试一试，如果使用1000000000作为你的程序的输入，你的程序是不是能在规定的上面规定的时限内运行出来。\n",
    "\n",
    "本题另一个要值得注意的地方是答案的大小不在你的语言默认的整型(int)范围内，如果使用整型来保存结果，会导致结果错误。\n",
    "\n",
    "如果你使用C++或C语言而且准备使用printf输出结果，则你的格式字符串应该写成%I64d以输出long long类型的整数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "22978ba2",
   "metadata": {},
   "outputs": [],
   "source": [
    "def sum():\n",
    "    n = int(input())\n",
    "    return n*(1+n)/2 # 等差数列时间短 直接使用a+b会超时\n",
    "s = int(sum())\n",
    "print(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5858a94f",
   "metadata": {},
   "source": [
    "### 试题 入门训练 A+B问题"
   ]
  },
  {
   "cell_type": "raw",
   "id": "9d765e3f",
   "metadata": {},
   "source": [
    "资源限制\n",
    "时间限制：1.0s   内存限制：256.0MB\n",
    "问题描述\n",
    "输入A、B，输出A+B。\n",
    "说明：在“问题描述”这部分，会给出试题的意思，以及所要求的目标。\n",
    "输入格式\n",
    "输入的第一行包括两个整数，由空格分隔，分别表示A、B。\n",
    "说明：“输入格式”是描述在测试你的程序时，所给的输入一定满足的格式。\n",
    "\n",
    "做题时你应该假设所给的输入是一定满足输入格式的要求的，所以你不需要对输入的格式进行检查。多余的格式检查可能会适得其反，使用你的程序错误。\n",
    "\n",
    "在测试的时候，系统会自动将输入数据输入到你的程序中，你不能给任何提示。比如，你在输入的时候提示“请输入A、B”之类的话是不需要的，这些多余的输出会使得你的程序被判定为错误。\n",
    "\n",
    "输出格式\n",
    "输出一行，包括一个整数，表示A+B的值。\n",
    "说明：“输出格式”是要求你的程序在输出结果的时候必须满足的格式。\n",
    "\n",
    "在输出时，你的程序必须满足这个格式的要求，不能少任何内容，也不能多任何内容。如果你的内容和输出格式要求的不一样，你的程序会被判断为错误，包括你输出了提示信息、中间调试信息、计时或者统计的信息等。\n",
    "\n",
    "样例输入\n",
    "12 45\n",
    "说明：“样例输入”给出了一组满足“输入格式”要求的输入的例子。\n",
    "\n",
    "这里给出的输入只是可能用来测试你的程序的一个输入，在测试的时候，还会有更多的输入用来测试你的程序。\n",
    "\n",
    "样例输出\n",
    "57\n",
    "说明：“样例输出”给出了一组满足“输出格式”要求的输出的例子。\n",
    "\n",
    "样例输出中的结果是和样例输入中的是对应的，因此，你可以使用样例的输入输出简单的检查你的程序。\n",
    "\n",
    "要特别指出的是，能够通过样例输入输出的程序并不一定是正确的程序，在测试的时候，会用很多组数据进行测试，而不局限于样例数据。有可能一个程序通过了样例数据，但测试的时候仍只能得0分，可能因为这个程序只在一些类似样例的特例中正确，而不具有通用性，再测试更多数据时会出现错误。\n",
    "\n",
    "比如，对于本题，如果你写一个程序不管输入是什么都输入57，则样例数据是对的，但是测试其他数据，哪怕输入是1和2，这个程序也输出57，则对于其他数据这个程序都不正确。\n",
    "\n",
    "数据规模与约定\n",
    "-10000 <= A, B <= 10000。\n",
    "说明：“数据规模与约定”中给出了试题中主要参数的范围。\n",
    "\n",
    "这个范围对于解题非常重要，不同的数据范围会导致试题需要使用不同的解法来解决。比如本题中给的A、B范围不大，可以使用整型(int)来保存，如果范围更大，超过int的范围，则要考虑其他方法来保存大数。\n",
    "\n",
    "有一些范围在方便的时候是在“问题描述”中直接给的，所以在做题时不仅要看这个范围，还要注意问题描述。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3aed02f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "a, b = map(int,input().split())\n",
    "print(a+b)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "24ebf619",
   "metadata": {},
   "source": [
    "# 基础练习"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7dc6d7ce",
   "metadata": {},
   "source": [
    "### 试题 基础练习 数列排序"
   ]
  },
  {
   "cell_type": "raw",
   "id": "1674cc60",
   "metadata": {},
   "source": [
    "资源限制\n",
    "时间限制：1.0s   内存限制：512.0MB\n",
    "问题描述\n",
    "　　给定一个长度为n的数列，将这个数列按从小到大的顺序排列。1<=n<=200\n",
    "输入格式\n",
    "　　第一行为一个整数n。\n",
    "　　第二行包含n个整数，为待排序的数，每个整数的绝对值小于10000。\n",
    "输出格式\n",
    "　　输出一行，按从小到大的顺序输出排序后的数列。\n",
    "样例输入\n",
    "5\n",
    "8 3 6 4 9\n",
    "样例输出\n",
    "3 4 6 8 9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a3e222ca",
   "metadata": {},
   "outputs": [],
   "source": [
    "n = int(input())\n",
    "list = list(map(int, input().split()))\n",
    "list = sorted(list)\n",
    "for i in range(len(list)):\n",
    "    print(list[i], end= ' ')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3905c9a4",
   "metadata": {},
   "source": [
    "### 试题 基础练习 十六进制转八进制"
   ]
  },
  {
   "cell_type": "raw",
   "id": "52c5ae2d",
   "metadata": {},
   "source": [
    "资源限制\n",
    "时间限制：1.0s   内存限制：512.0MB\n",
    "问题描述\n",
    "　　给定n个十六进制正整数，输出它们对应的八进制数。\n",
    "\n",
    "输入格式\n",
    "　　输入的第一行为一个正整数n （1<=n<=10）。\n",
    "　　接下来n行，每行一个由0~9、大写字母A~F组成的字符串，表示要转换的十六进制正整数，每个十六进制数长度不超过100000。\n",
    "\n",
    "输出格式\n",
    "　　输出n行，每行为输入对应的八进制正整数。\n",
    "\n",
    "　　【注意】\n",
    "　　输入的十六进制数不会有前导0，比如012A。\n",
    "　　输出的八进制数也不能有前导0。\n",
    "\n",
    "样例输入\n",
    "　　2\n",
    "　　39\n",
    "　　123ABC\n",
    "\n",
    "样例输出\n",
    "　　71\n",
    "　　4435274\n",
    "\n",
    "　　【提示】\n",
    "　　先将十六进制数转换成某进制数，再由某进制数转换成八进制。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "54039d9d",
   "metadata": {},
   "outputs": [],
   "source": [
    "n = int(input())\n",
    "\n",
    "results = list()\n",
    "for line in range(n):\n",
    "    num = input()\n",
    "    ans = format(int(num, 16), 'o')\n",
    "    results.append(ans)\n",
    "for value in results:\n",
    "    print(value)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9cb3ba0b",
   "metadata": {},
   "source": [
    "### 试题 基础练习 十六进制转十进制"
   ]
  },
  {
   "cell_type": "raw",
   "id": "4039174e",
   "metadata": {},
   "source": [
    "资源限制\n",
    "时间限制：1.0s   内存限制：512.0MB\n",
    "问题描述\n",
    "　　从键盘输入一个不超过8位的正的十六进制数字符串，将它转换为正的十进制数后输出。\n",
    "　　注：十六进制数中的10~15分别用大写的英文字母A、B、C、D、E、F表示。\n",
    "样例输入\n",
    "FFFF\n",
    "样例输出\n",
    "65535"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "be1dfba2",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "num = input()\n",
    "print(int(num,16))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "00d2fe08",
   "metadata": {},
   "source": [
    "### 试题 基础练习 十进制转十六进制"
   ]
  },
  {
   "cell_type": "raw",
   "id": "b246a643",
   "metadata": {},
   "source": [
    "资源限制\n",
    "时间限制：1.0s   内存限制：512.0MB\n",
    "问题描述\n",
    "　　十六进制数是在程序设计时经常要使用到的一种整数的表示方式。它有0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F共16个符号，分别表示十进制数的0至15。十六进制的计数方法是满16进1，所以十进制数16在十六进制中是10，而十进制的17在十六进制中是11，以此类推，十进制的30在十六进制中是1E。\n",
    "　　给出一个非负整数，将它表示成十六进制的形式。\n",
    "输入格式\n",
    "　　输入包含一个非负整数a，表示要转换的数。0<=a<=2147483647\n",
    "输出格式\n",
    "　　输出这个整数的16进制表示\n",
    "样例输入\n",
    "30\n",
    "样例输出\n",
    "1E"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6e33d853",
   "metadata": {},
   "outputs": [],
   "source": [
    "num = int(input())\n",
    "print(format(num, 'X'))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79a5c1dd",
   "metadata": {},
   "source": [
    "### 试题 基础练习 特殊回文数"
   ]
  },
  {
   "cell_type": "raw",
   "id": "20d14367",
   "metadata": {},
   "source": [
    "资源限制\n",
    "时间限制：1.0s   内存限制：512.0MB\n",
    "问题描述\n",
    "　　123321是一个非常特殊的数，它从左边读和从右边读是一样的。\n",
    "　　输入一个正整数n， 编程求所有这样的五位和六位十进制数，满足各位数字之和等于n 。\n",
    "输入格式\n",
    "　　输入一行，包含一个正整数n。\n",
    "输出格式\n",
    "　　按从小到大的顺序输出满足条件的整数，每个整数占一行。\n",
    "样例输入\n",
    "52\n",
    "样例输出\n",
    "899998\n",
    "989989\n",
    "998899\n",
    "数据规模和约定\n",
    "　　1<=n<=54。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "580c5945",
   "metadata": {},
   "outputs": [],
   "source": [
    "num = int(input())\n",
    "for n in range(10000, 1000000):\n",
    "    n = str(n)\n",
    "    if n == n[::-1]:\n",
    "        if sum([int(i) for i in n]) == num:\n",
    "            print(n)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "185be562",
   "metadata": {},
   "source": [
    "### 试题 基础练习 回文数"
   ]
  },
  {
   "cell_type": "raw",
   "id": "f8c9395f",
   "metadata": {},
   "source": [
    "资源限制\n",
    "时间限制：1.0s   内存限制：512.0MB\n",
    "问题描述\n",
    "　　1221是一个非常特殊的数，它从左边读和从右边读是一样的，编程求所有这样的四位十进制数。\n",
    "输出格式\n",
    "　　按从小到大的顺序输出满足条件的四位十进制数。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "44737154",
   "metadata": {},
   "outputs": [],
   "source": [
    "for n in range(1000, 10000):\n",
    "    n = str(n)\n",
    "    if n == n[::-1]:\n",
    "        print(n)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f7082c94",
   "metadata": {},
   "source": [
    "### 试题 基础练习 特殊的数字"
   ]
  },
  {
   "cell_type": "raw",
   "id": "7b2c257a",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　153是一个非常特殊的数，它等于它的每位数字的立方和，即153=1*1*1+5*5*5+3*3*3。编程求所有满足这种条件的三位十进制数。\n",
    "输出格式\n",
    "　　按从小到大的顺序输出满足条件的三位十进制数，每个数占一行。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "486bda82",
   "metadata": {},
   "outputs": [],
   "source": [
    "for n in range(100,1000):\n",
    "    if sum([pow(int(i), 3) for i in str(n)]) == n:\n",
    "        print(n)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d7e04b12",
   "metadata": {},
   "source": [
    "### 试题 基础练习 杨辉三角形"
   ]
  },
  {
   "cell_type": "raw",
   "id": "4e552cff",
   "metadata": {},
   "source": [
    "问题描述\n",
    "杨辉三角形又称Pascal三角形，它的第i+1行是(a+b)i的展开式的系数。\n",
    "\n",
    "　　\n",
    "它的一个重要性质是：三角形中的每个数字等于它两肩上的数字相加。\n",
    "\n",
    "　　\n",
    "下面给出了杨辉三角形的前4行：\n",
    "\n",
    "　　\n",
    "   1\n",
    "\n",
    "　　\n",
    "  1 1\n",
    "\n",
    "　　\n",
    " 1 2 1\n",
    "\n",
    "　　\n",
    "1 3 3 1\n",
    "\n",
    "　　\n",
    "给出n，输出它的前n行。\n",
    "\n",
    "输入格式\n",
    "输入包含一个数n。\n",
    "\n",
    "输出格式\n",
    "输出杨辉三角形的前n行。每一行从这一行的第一个数开始依次输出，中间使用一个空格分隔。请不要在前面输出多余的空格。\n",
    "样例输入\n",
    "4\n",
    "样例输出\n",
    "1\n",
    "1 1\n",
    "1 2 1\n",
    "1 3 3 1\n",
    "数据规模与约定\n",
    "1 <= n <= 34。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "61520acd",
   "metadata": {},
   "outputs": [],
   "source": [
    "def triangles(num):\n",
    "    n = [1]\n",
    "    while num > 0:\n",
    "        for i in range(len(n)):\n",
    "            print(n[i], end=' ') # 将列表转为要求的格式\n",
    "        \n",
    "        # 三角形中的每个数字等于它两肩上的数字相加。\n",
    "        tmp = list()\n",
    "        for i in range(len(n) - 1):\n",
    "            tmp.append(n[i] + n[i+1])\n",
    "        \n",
    "        n = [1] + tmp + [1]\n",
    "        num -= 1\n",
    "        print()                  # 换行\n",
    "if __name__ == '__main__':\n",
    "    n = int(input())\n",
    "    triangles(n)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "799184cf",
   "metadata": {},
   "source": [
    "### 试题 基础练习 查找整数"
   ]
  },
  {
   "cell_type": "raw",
   "id": "ed0c65d2",
   "metadata": {},
   "source": [
    "问题描述\n",
    "给出一个包含n个整数的数列，问整数a在数列中的第一次出现是第几个。\n",
    "\n",
    "输入格式\n",
    "第一行包含一个整数n。\n",
    "\n",
    "第二行包含n个非负整数，为给定的数列，数列中的每个数都不大于10000。\n",
    "\n",
    "第三行包含一个整数a，为待查找的数。\n",
    "\n",
    "输出格式\n",
    "如果a在数列中出现了，输出它第一次出现的位置(位置从1开始编号)，否则输出-1。\n",
    "样例输入\n",
    "6\n",
    "1 9 4 8 3 9\n",
    "9\n",
    "样例输出\n",
    "2\n",
    "数据规模与约定\n",
    "1 <= n <= 1000。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e48db0ce",
   "metadata": {},
   "outputs": [],
   "source": [
    "n = input()\n",
    "l = input().split()\n",
    "num = input()\n",
    "if num not in l :\n",
    "    print(-1)\n",
    "else:\n",
    "    print(l.index(num) + 1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4794af9a",
   "metadata": {},
   "source": [
    "### 试题 基础练习 数列特征"
   ]
  },
  {
   "cell_type": "raw",
   "id": "4135e2d2",
   "metadata": {},
   "source": [
    "问题描述\n",
    "给出n个数，找出这n个数的最大值，最小值，和。\n",
    "\n",
    "输入格式\n",
    "第一行为整数n，表示数的个数。\n",
    "\n",
    "第二行有n个数，为给定的n个数，每个数的绝对值都小于10000。\n",
    "\n",
    "输出格式\n",
    "输出三行，每行一个整数。第一行表示这些数中的最大值，第二行表示这些数中的最小值，第三行表示这些数的和。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2634e84a",
   "metadata": {},
   "outputs": [],
   "source": [
    "n = input()\n",
    "l = list(map(int , input().split()))\n",
    "print(min(l))\n",
    "print(max(l))\n",
    "print(sum(l))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "71a7bb6f",
   "metadata": {},
   "source": [
    "### 试题 基础练习 字母图形"
   ]
  },
  {
   "cell_type": "raw",
   "id": "bc32dba3",
   "metadata": {},
   "source": [
    "问题描述\n",
    "利用字母可以组成一些美丽的图形，下面给出了一个例子：\n",
    "\n",
    "ABCDEFG\n",
    "\n",
    "BABCDEF\n",
    "\n",
    "CBABCDE\n",
    "\n",
    "DCBABCD\n",
    "\n",
    "EDCBABC\n",
    "\n",
    "这是一个5行7列的图形，请找出这个图形的规律，并输出一个n行m列的图形。\n",
    "\n",
    "输入格式\n",
    "输入一行，包含两个整数n和m，分别表示你要输出的图形的行数的列数。\n",
    "输出格式\n",
    "输出n行，每个m个字符，为你的图形。\n",
    "样例输入\n",
    "5 7\n",
    "样例输出\n",
    "ABCDEFG\n",
    "BABCDEF\n",
    "CBABCDE\n",
    "DCBABCD\n",
    "EDCBABC"
   ]
  },
  {
   "cell_type": "raw",
   "id": "ac5d68a7",
   "metadata": {},
   "source": [
    "ASCII码转字符：chr(int)    0-127\n",
    "\n",
    "字符转ASCII码：ord(str)    单个可见ASCII字符串，不能中文和非ASCII码里的字符\n",
    "\n",
    "0～32及127 (共33个)是控制字符或通信专用字符（其余为可显示字符），如控制符：LF（换行）、CR（回车）、FF（换页）、DEL（删除）、BS（退格)、BEL（响铃）等；通信专用字符：SOH（文头）、EOT（文尾）、ACK（确认）等；ASCII值为8、9、10 和13 分别转换为退格、制表、换行和回车字符。\n",
    "\n",
    "33-47          ! \" # $ % & ' ( ) * + , - . /\n",
    "48-57          数字0-9\n",
    "123-126      { | } ~\n",
    "97-122        小写字母a-z\n",
    "91-96          : ; < = > ? @\n",
    "65-90          大写字母A-Z\n",
    "58-64          [ \\ ] ^ _ `"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ba837b19",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "row, colunm = map(int, input().split())\n",
    "l = [chr(65+i) for i in range(colunm)]\n",
    "\n",
    "\n",
    "for i in range(row):\n",
    "    new_l = l[0:i+1][::-1] + l [1:colunm-i]\n",
    "    \n",
    "    print(\"\".join(new_l))\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "547451a7",
   "metadata": {},
   "source": [
    "### 试题 基础练习 01字串"
   ]
  },
  {
   "cell_type": "raw",
   "id": "5e121698",
   "metadata": {},
   "source": [
    "问题描述\n",
    "对于长度为5位的一个01串，每一位都可能是0或1，一共有32种可能。它们的前几个是：\n",
    "\n",
    "00000\n",
    "\n",
    "00001\n",
    "\n",
    "00010\n",
    "\n",
    "00011\n",
    "\n",
    "00100\n",
    "\n",
    "请按从小到大的顺序输出这32种01串。\n",
    "\n",
    "输入格式\n",
    "本试题没有输入。\n",
    "输出格式\n",
    "输出32行，按从小到大的顺序每行一个长度为5的01串。\n",
    "样例输出\n",
    "00000\n",
    "00001\n",
    "00010\n",
    "00011\n",
    "<以下部分省略>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9eec2326",
   "metadata": {},
   "source": [
    "二进制：'0b'\n",
    "八进制：'o'\n",
    "十六进制：'X'\n",
    "转十进制：int(value, 16 / 8 / 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "14d63212",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(32):\n",
    "    ans = str(format(i, '0b'))\n",
    "    print('0' * (5 - len(ans)) + ans)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "554c5541",
   "metadata": {},
   "source": [
    "### 试题 基础练习 闰年判断"
   ]
  },
  {
   "cell_type": "raw",
   "id": "3ad42b91",
   "metadata": {},
   "source": [
    "问题描述\n",
    "给定一个年份，判断这一年是不是闰年。\n",
    "\n",
    "当以下情况之一满足时，这一年是闰年：\n",
    "\n",
    "1. 年份是4的倍数而不是100的倍数；\n",
    "\n",
    "2. 年份是400的倍数。\n",
    "\n",
    "其他的年份都不是闰年。\n",
    "\n",
    "输入格式\n",
    "输入包含一个整数y，表示当前的年份。\n",
    "输出格式\n",
    "输出一行，如果给定的年份是闰年，则输出yes，否则输出no。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3282314d",
   "metadata": {},
   "outputs": [],
   "source": [
    "year = int(input())\n",
    "\n",
    "if year % 4 == 0 and year % 100 != 0:\n",
    "    print(\"yes\")\n",
    "\n",
    "elif year % 400 == 0:\n",
    "    print(\"yes\")\n",
    "    \n",
    "else:\n",
    "    print(\"no\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3cfcde82",
   "metadata": {},
   "source": [
    "### 试题 基础练习 阶乘计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6de80774",
   "metadata": {},
   "outputs": [],
   "source": [
    "n = int(input())\n",
    "\n",
    "tmp = 1 \n",
    "for i in range(1,n+1):\n",
    "    tmp = tmp * i\n",
    "\n",
    "print(tmp)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "01e016ac",
   "metadata": {},
   "source": [
    "### 试题 基础练习 高精度加法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "667ef218",
   "metadata": {},
   "outputs": [],
   "source": [
    "# python 大数\n",
    "a = int(input())\n",
    "b = int(input())\n",
    "print(a+b)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9d6a6e9a",
   "metadata": {},
   "source": [
    "### 试题 基础练习 Huffuman树"
   ]
  },
  {
   "cell_type": "raw",
   "id": "22550000",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　Huffman树在编码中有着广泛的应用。在这里，我们只关心Huffman树的构造过程。\n",
    "　　给出一列数{pi}={p0, p1, …, pn-1}，用这列数构造Huffman树的过程如下：\n",
    "　　1. 找到{pi}中最小的两个数，设为pa和pb，将pa和pb从{pi}中删除掉，然后将它们的和加入到{pi}中。这个过程的费用记为pa + pb。\n",
    "　　2. 重复步骤1，直到{pi}中只剩下一个数。\n",
    "　　在上面的操作过程中，把所有的费用相加，就得到了构造Huffman树的总费用。\n",
    "　　本题任务：对于给定的一个数列，现在请你求出用该数列构造Huffman树的总费用。\n",
    "\n",
    "　　例如，对于数列{pi}={5, 3, 8, 2, 9}，Huffman树的构造过程如下：\n",
    "　　1. 找到{5, 3, 8, 2, 9}中最小的两个数，分别是2和3，从{pi}中删除它们并将和5加入，得到{5, 8, 9, 5}，费用为5。\n",
    "　　2. 找到{5, 8, 9, 5}中最小的两个数，分别是5和5，从{pi}中删除它们并将和10加入，得到{8, 9, 10}，费用为10。\n",
    "　　3. 找到{8, 9, 10}中最小的两个数，分别是8和9，从{pi}中删除它们并将和17加入，得到{10, 17}，费用为17。\n",
    "　　4. 找到{10, 17}中最小的两个数，分别是10和17，从{pi}中删除它们并将和27加入，得到{27}，费用为27。\n",
    "　　5. 现在，数列中只剩下一个数27，构造过程结束，总费用为5+10+17+27=59。\n",
    "输入格式\n",
    "　　输入的第一行包含一个正整数n（n<=100）。\n",
    "　　接下来是n个正整数，表示p0, p1, …, pn-1，每个数不超过1000。\n",
    "输出格式\n",
    "　　输出用这些数构造Huffman树的总费用。\n",
    "样例输入\n",
    "5\n",
    "5 3 8 2 9\n",
    "样例输出\n",
    "59"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7fdc091c",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "n = int(input())\n",
    "\n",
    "nums = list(map(int,input().split()))\n",
    "\n",
    "pay = 0\n",
    "while len(nums) != 1:\n",
    "    min_1 = min(nums)\n",
    "    nums.remove(min_1)\n",
    "    min_2 = min(nums)\n",
    "    nums.remove(min_2)\n",
    "    \n",
    "    _sum = min_1 +min_2\n",
    "    \n",
    "    nums.append(_sum)\n",
    "\n",
    "    pay += _sum\n",
    "\n",
    "        \n",
    "    \n",
    "print(pay)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cdc4fb5d",
   "metadata": {},
   "source": [
    "### ！！！试题 基础练习 2n皇后问题"
   ]
  },
  {
   "cell_type": "raw",
   "id": "34d197d7",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　给定一个n*n的棋盘，棋盘中有一些位置不能放皇后。现在要向棋盘中放入n个黑皇后和n个白皇后，使任意的两个黑皇后都不在同一行、同一列或同一条对角线上，任意的两个白皇后都不在同一行、同一列或同一条对角线上。问总共有多少种放法？n小于等于8。\n",
    "输入格式\n",
    "　　输入的第一行为一个整数n，表示棋盘的大小。\n",
    "　　接下来n行，每行n个0或1的整数，如果一个整数为1，表示对应的位置可以放皇后，如果一个整数为0，表示对应的位置不可以放皇后。\n",
    "输出格式\n",
    "　　输出一个整数，表示总共有多少种放法。\n",
    "样例输入\n",
    "4\n",
    "1 1 1 1\n",
    "1 1 1 1\n",
    "1 1 1 1\n",
    "1 1 1 1\n",
    "样例输出\n",
    "2\n",
    "样例输入\n",
    "4\n",
    "1 0 1 1\n",
    "1 1 1 1\n",
    "1 1 1 1\n",
    "1 1 1 1\n",
    "样例输出\n",
    "0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "faebdb75",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "e2935908",
   "metadata": {},
   "source": [
    "### 试题 基础练习 报时助手"
   ]
  },
  {
   "cell_type": "raw",
   "id": "70543850",
   "metadata": {},
   "source": [
    "问题描述\n",
    "\n",
    "　　给定当前的时间，请用英文的读法将它读出来。\n",
    "　　时间用时h和分m表示，在英文的读法中，读一个时间的方法是：\n",
    "　　如果m为0，则将时读出来，然后加上“o'clock”，如3:00读作“three o'clock”。\n",
    "　　如果m不为0，则将时读出来，然后将分读出来，如5:30读作“five thirty”。\n",
    "　　时和分的读法使用的是英文数字的读法，其中0~20读作：\n",
    "　　0:zero, 1: one, 2:two, 3:three, 4:four, 5:five, 6:six, 7:seven, 8:eight, 9:nine, 10:ten, 11:eleven, 12:twelve, 13:thirteen, 14:fourteen, 15:fifteen, 16:sixteen, 17:seventeen, 18:eighteen, 19:nineteen, 20:twenty。\n",
    "　　30读作thirty，40读作forty，50读作fifty。\n",
    "　　对于大于20小于60的数字，首先读整十的数，然后再加上个位数。如31首先读30再加1的读法，读作“thirty one”。\n",
    "　　按上面的规则21:54读作“twenty one fifty four”，9:07读作“nine seven”，0:15读作“zero fifteen”。\n",
    "输入格式\n",
    "\n",
    "　　输入包含两个非负整数h和m，表示时间的时和分。非零的数字前没有前导0。h小于24，m小于60。\n",
    "输出格式\n",
    "\n",
    "　　输出时间时刻的英文。\n",
    "样例输入\n",
    "\n",
    "0 15\n",
    "样例输出\n",
    "\n",
    "zero fifteen”。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "333aaa43",
   "metadata": {},
   "outputs": [],
   "source": [
    "h, m = map(int, input().split())\n",
    "\n",
    "num = {0:'zero', 1: 'one', 2:'two', 3:'three', 4:'four', 5:'five', \n",
    "       6:'six', 7:'seven', 8:'eight', 9:'nine', 10:'ten', 11:'eleven', \n",
    "       12:'twelve', 13:'thirteen', 14:'fourteen', 15:'fifteen', 16:'sixteen', \n",
    "       17:'seventeen', 18:'eighteen', 19:'nineteen', 20:'twenty', 30:'thirty', 40:'forty', 50:'fifty'}\n",
    "\n",
    "if m == 0:\n",
    "    \n",
    "    print(num[h] + \"o'clock\")\n",
    "            \n",
    "else:      \n",
    "    m_s = m % 10\n",
    "    m_t = m - m_s\n",
    "    print(num[h] + \" \" + num[m_t] + \" \"+ num[m_s])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7fa224a8",
   "metadata": {},
   "source": [
    "### ！！！试题 基础练习 回形取数"
   ]
  },
  {
   "cell_type": "raw",
   "id": "dfb2e3ed",
   "metadata": {},
   "source": [
    "问题描述\n",
    "\n",
    "　　回形取数就是沿矩阵的边取数，若当前方向上无数可取或已经取过，则左转90度。一开始位于矩阵左上角，方向向下。\n",
    "\n",
    "输入格式\n",
    "\n",
    "　　输入第一行是两个不超过200的正整数m, n，表示矩阵的行和列。接下来m行每行n个整数，表示这个矩阵。\n",
    "\n",
    "输出格式\n",
    "\n",
    "　　输出只有一行，共mn个数，为输入矩阵回形取数得到的结果。数之间用一个空格分隔，行末不要有多余的空格。\n",
    "\n",
    "样例输入\n",
    "\n",
    "3 3\n",
    "1 2 3\n",
    "4 5 6\n",
    "7 8 9\n",
    "\n",
    "样例输出\n",
    "\n",
    "1 4 7 8 9 6 3 2 5\n",
    "\n",
    "样例输入\n",
    "\n",
    "3 2\n",
    "1 2\n",
    "3 4\n",
    "5 6\n",
    "样例输出\n",
    "1 3 5 6 4 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "76c7f111",
   "metadata": {},
   "outputs": [],
   "source": [
    "n, m = map(int, input().split())\n",
    "tmp = [] # 存放答案\n",
    "vis = [[0 for i in range(m)] for i in range(n)] # 验证位置是否走过 当vis[x][y] = 1时即为走过\n",
    "arr = [list(map(int, input().split())) for _ in range(n)]\n",
    "# 注意: 向下为x, 向右为y\n",
    "x = 0 # 当前纵坐标\n",
    "y = 0 # 当前横坐标\n",
    "while len(tmp) < n*m :\n",
    "    while x < n and vis[x][y] == 0:\n",
    "        tmp.append(arr[x][y])\n",
    "        vis[x][y] = 1\n",
    "        x += 1  # 纵坐标加一\n",
    "    x -= 1 # 将上步多余的步数删除,防止溢出\n",
    "    y += 1 # 将横坐标右移\n",
    "    while y < m and vis[x][y] == 0:\n",
    "        tmp.append(arr[x][y])\n",
    "        vis[x][y] = 1\n",
    "        y += 1\n",
    "    x -= 1 # 将纵坐标减一\n",
    "    y -= 1 # 将上步多余步数删除,防止溢出\n",
    "    while x >= 0 and vis[x][y] == 0:\n",
    "        tmp.append(arr[x][y])\n",
    "        vis[x][y] = 1\n",
    "        x -= 1 # 将纵坐标上移\n",
    "    x += 1 # 将上步多余步数删除,防止溢出\n",
    "    y -= 1 # 将横坐标左移\n",
    "    while y >=0 and vis[x][y] == 0:\n",
    "        tmp.append(arr[x][y])\n",
    "        vis[x][y] = 1\n",
    "        y -= 1 # 将横坐标左移\n",
    "    y += 1 # 将上步多余步数删除\n",
    "    x += 1 # 将纵坐标下移\n",
    "\n",
    "# 输出数据\n",
    "for i in range(len(tmp)):\n",
    "    print(tmp[i], end=' ')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7089d258",
   "metadata": {},
   "source": [
    "### 试题 基础练习 龟兔赛跑预测"
   ]
  },
  {
   "cell_type": "raw",
   "id": "049c1971",
   "metadata": {},
   "source": [
    "\n",
    "题目描述\n",
    "话说这个世界上有各种各样的兔子和乌龟，但是研究发现，所有的兔子和乌龟都有一个共同的特点——喜欢赛跑。于是世界上各个角落都不断在发生着乌龟和兔子的比赛，小华对此很感兴趣，于是决定研究不同兔子和乌龟的赛跑。他发现，兔子虽然跑比乌龟快，但它们有众所周知的毛病——骄傲且懒惰，于是在与乌龟的比赛中，一旦任一秒结束后兔子发现自己领先t米或以上，它们就会停下来休息s秒。对于不同的兔子，t，s的数值是不同的，但是所有的乌龟却是一致——它们不到终点决不停止。\n",
    "然而有些比赛相当漫长，全程观看会耗费大量时间，而小华发现只要在每场比赛开始后记录下兔子和乌龟的数据——兔子的速度v1（表示每秒兔子能跑v1米），乌龟的速度v2，以及兔子对应的t，s值，以及赛道的长度l——就能预测出比赛的结果。但是小华很懒，不想通过手工计算推测出比赛的结果，于是他找到了你——清华大学计算机系的高才生——请求帮助，请你写一个程序，对于输入的一场比赛的数据v1，v2，t，s，l，预测该场比赛的结果。\n",
    "输入解释\n",
    "输入只有一行，包含用空格隔开的五个正整数v1，v2，t，s，l，其中(v1,v2<=100;t<=300;s<=10;l<=10000且为v1,v2的公倍数)\n",
    "输出解释\n",
    "输出包含两行，第一行输出比赛结果——一个大写字母“T”或“R”或“D”，分别表示乌龟获胜，兔子获胜，或者两者同时到达终点。\n",
    "第二行输出一个正整数，表示获胜者（或者双方同时）到达终点所耗费的时间（秒数）。\n",
    "输入样例 1\n",
    "\n",
    "10 5 5 2 20\n",
    "\n",
    "输出样例 1\n",
    "\n",
    "D\n",
    "4\n",
    "\n",
    "\n",
    "输入样例 2\n",
    "\n",
    "10 5 5 1 20\n",
    "\n",
    "输出样例 2\n",
    "\n",
    "R\n",
    "3\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5b4814f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "v1, v2, t, s, l = map(int, input().split())\n",
    "\n",
    "times = t / (v1 - v2)\n",
    "\n",
    "t_times = l / v2\n",
    "r_times = l / v1\n",
    "\n",
    "if r_times < times :\n",
    "    print('R')\n",
    "    print(int(r_times))\n",
    "\n",
    "else :\n",
    "    if t_times < r_times + s:\n",
    "        print('T')\n",
    "        print(int(t_times))\n",
    "    \n",
    "    if t_times > r_times + s:\n",
    "        print('R')\n",
    "        print(int(r_times + s))\n",
    "        \n",
    "    if t_times == r_times + s:\n",
    "        print('D')\n",
    "        print(int(t_times))\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "14d5b9e8",
   "metadata": {},
   "source": [
    "### 试题 基础练习 芯片测试"
   ]
  },
  {
   "cell_type": "raw",
   "id": "40c079ce",
   "metadata": {},
   "source": [
    "问题描述\n",
    "\n",
    "　　有n（2≤n≤20）块芯片，有好有坏，已知好芯片比坏芯片多。\n",
    "　　每个芯片都能用来测试其他芯片。用好芯片测试其他芯片时，能正确给出被测试芯片是好还是坏。而用坏芯片测试其他芯片时，会随机给出好或是坏的测试结果（即此结果与被测试芯片实际的好坏无关）。\n",
    "　　给出所有芯片的测试结果，问哪些芯片是好芯片。\n",
    "\n",
    "输入格式\n",
    "\n",
    "　　输入数据第一行为一个整数n，表示芯片个数。\n",
    "　　第二行到第n+1行为n*n的一张表，每行n个数据。表中的每个数据为0或1，在这n行中的第i行第j列（1≤i, j≤n）的数据表示用第i块芯片测试第j块芯片时得到的测试结果，1表示好，0表示坏，i=j时一律为1（并不表示该芯片对本身的测试结果。芯片不能对本身进行测试）。\n",
    "\n",
    "输出格式\n",
    "\n",
    "　　按从小到大的顺序输出所有好芯片的编号\n",
    "\n",
    "样例输入\n",
    "\n",
    "3\n",
    "1 0 1\n",
    "0 1 0\n",
    "1 0 1\n",
    "\n",
    "样例输出\n",
    "\n",
    "1 3"
   ]
  },
  {
   "cell_type": "raw",
   "id": "9cc562bf",
   "metadata": {},
   "source": [
    "用好芯片测试其他芯片时，能正确给出被测试芯片是好还是坏。\n",
    "\n",
    "而用坏芯片测试其他芯片时，会随机给出好或是坏的测试结果（即此结果与被测试芯片实际的好坏无关）\n",
    "\n",
    "在这n行中的第i行第j列（1≤i, j≤n）的数据表示用第i块芯片测试第j块芯片时得到的测试结果，1表示好，0表示坏，i=j时一律为1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "acb9d2cd",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "n = int(input())\n",
    "\n",
    "data = dict()\n",
    "for _ in range(n):\n",
    "    data.setdefault(_,list(map(int,input().split())))\n",
    "\n",
    "goods = list()\n",
    "for i in data.keys():\n",
    "    for j in range(len(data[i])):\n",
    "        if data[i][j] == 1:\n",
    "            if data[0][i] == 1:\n",
    "                goods.append(j+1)\n",
    "\n",
    "goods = set(goods)\n",
    "for value in goods:\n",
    "    print(value, end = ' ')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b6be8908",
   "metadata": {},
   "source": [
    "### 试题 基础练习 FJ的字符串"
   ]
  },
  {
   "cell_type": "raw",
   "id": "bef17627",
   "metadata": {},
   "source": [
    "资源限制\n",
    "\n",
    "时间限制：1.0s   内存限制：512.0MB\n",
    "\n",
    "问题描述\n",
    "\n",
    "　　FJ在沙盘上写了这样一些字符串：\n",
    "　　A1 = “A”\n",
    "　　A2 = “ABA”\n",
    "　　A3 = “ABACABA”\n",
    "　　A4 = “ABACABADABACABA”\n",
    "　　… …\n",
    "　　你能找出其中的规律并写所有的数列AN吗？\n",
    "\n",
    "输入格式\n",
    "\n",
    "　　仅有一个数：N ≤ 26。\n",
    "\n",
    "输出格式\n",
    "\n",
    "　　请输出相应的字符串AN，以一个换行符结束。输出中不得含有多余的空格或换行、回车符。\n",
    "\n",
    "样例输入\n",
    "\n",
    "3\n",
    "\n",
    "样例输出\n",
    "\n",
    "ABACABA\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13fd1900",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "n = int(input())\n",
    "string = ''\n",
    "\n",
    "for i in range(1, n+1):\n",
    "    string = string + chr(i+64) + string\n",
    "\n",
    "print(string)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "936bf07c",
   "metadata": {},
   "source": [
    "### 试题 基础练习 Sine之舞"
   ]
  },
  {
   "cell_type": "raw",
   "id": "d96b45e1",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　最近FJ为他的奶牛们开设了数学分析课，FJ知道若要学好这门课，必须有一个好的三角函数基本功。所以他准备和奶牛们做一个“Sine之舞”的游戏，寓教于乐，提高奶牛们的计算能力。\n",
    "　　不妨设\n",
    "　　An=sin(1–sin(2+sin(3–sin(4+…sin(n))…)\n",
    "　　Sn=(…(A1+n)A2+n-1)A3+…+2)An+1\n",
    "　　FJ想让奶牛们计算Sn的值，请你帮助FJ打印出Sn的完整表达式，以方便奶牛们做题。\n",
    "输入格式\n",
    "　　仅有一个数：N<201。\n",
    "输出格式\n",
    "　　请输出相应的表达式Sn，以一个换行符结束。输出中不得含有多余的空格或换行、回车符。\n",
    "样例输入\n",
    "3\n",
    "样例输出\n",
    "((sin(1)+3)sin(1–sin(2))+2)sin(1–sin(2+sin(3)))+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5515deb1",
   "metadata": {},
   "outputs": [],
   "source": [
    "def Sine_An(n, k):\n",
    "    if n == k: # 返回值\n",
    "        return\n",
    "    print('sin(%d' % (n+1), end='')\n",
    "\n",
    "    if n + 1 != k: # 当n小于输入的值,即后面还有式子\n",
    "        if n % 2 == 1: # 如果n是奇数 输出+号\n",
    "            print('+', end='')\n",
    "        else:         # 如果n是偶数 输出-号\n",
    "            print('-', end='')\n",
    "    else:          # 如果后面没有式子输出右括号\n",
    "        print(')', end='')\n",
    "\n",
    "    Sine_An(n+1, k)\n",
    "\n",
    "def Sine_Sn(n):\n",
    "    k = t = 1\n",
    "\n",
    "    if n == 0:\n",
    "        return\n",
    "\n",
    "    for i in range(n-1): # 补全左边括号\n",
    "        print('(', end='')\n",
    "\n",
    "    while n != 0:\n",
    "        Sine_An(0,k)\n",
    "        for i in range(t-1):\n",
    "            print(')', end='') # 补全An的右括号\n",
    "        print('+%d' % n, end='')\n",
    "        if n !=1:\n",
    "            print(')', end='')\n",
    "\n",
    "        k+=1\n",
    "        t+=1\n",
    "        n-=1\n",
    "if __name__ == '__main__':\n",
    "    n = int(input())\n",
    "    Sine_Sn(n)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "feec4842",
   "metadata": {},
   "source": [
    "### 试题 基础练习 数的读法"
   ]
  },
  {
   "cell_type": "raw",
   "id": "ef81edb0",
   "metadata": {},
   "source": [
    "资源限制\n",
    "时间限制：1.0s 内存限制：512.0MB\n",
    "问题描述\n",
    "　　Tom教授正在给研究生讲授一门关于基因的课程，有一件事情让他颇为头疼：一条染色体上有成千上万个碱基对，它们从0开始编号，到几百万，几千万，甚至上亿。\n",
    "　　比如说，在对学生讲解第1234567009号位置上的碱基时，光看着数字是很难准确的念出来的。\n",
    "　　所以，他迫切地需要一个系统，然后当他输入12 3456 7009时，会给出相应的念法：\n",
    "　　十二亿三千四百五十六万七千零九\n",
    "　　用汉语拼音表示为\n",
    "　　shi er yi san qian si bai wu shi liu wan qi qian ling jiu\n",
    "　　这样他只需要照着念就可以了。\n",
    "　　你的任务是帮他设计这样一个系统：给定一个阿拉伯数字串，你帮他按照中文读写的规范转为汉语拼音字串，相邻的两个音节用一个空格符格开。\n",
    "　　注意必须严格按照规范，比如说“10010”读作“yi wan ling yi shi”而不是“yi wan ling shi”，“100000”读作“shi wan”而不是“yi shi wan”，“2000”读作“er qian”而不是“liang qian”。\n",
    "输入格式\n",
    "　　有一个数字串，数值大小不超过2,000,000,000。\n",
    "输出格式\n",
    "　　是一个由小写英文字母，逗号和空格组成的字符串，表示该数的英文读法。\n",
    "样例输入\n",
    "1234567009\n",
    "样例输出\n",
    "shi er yi san qian si bai wu shi liu wan qi qian ling jiu"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6829e315",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "num = int(input())\n",
    "\n",
    "data = {0: 'ling', 1: 'yi', 2: 'er', 3: 'san', 4: 'si', \n",
    "        5: 'wu',6: 'liu', 7: 'qi', 8: 'ba', 9: 'jiu'}\n",
    "\n",
    "string = list()\n",
    "\n",
    "yi = num // 100000000\n",
    "num = num - yi*100000000\n",
    "\n",
    "wan = num // 10000\n",
    "num = num - wan*10000\n",
    "\n",
    "qian = num // 1000\n",
    "num = num - qian*1000\n",
    "\n",
    "bai = num // 100\n",
    "num = num - bai*100\n",
    "\n",
    "shi = num // 10\n",
    "num = num - shi*10\n",
    "\n",
    "ge = num \n",
    "\n",
    "result = yi//100\n",
    "if result != 0:\n",
    "    string.append(data[result])\n",
    "    string.append('bai')\n",
    "    \n",
    "result = yi%100//10\n",
    "if result != 0:\n",
    "    string.append(data[result])\n",
    "    string.append('shi')\n",
    "    \n",
    "result = yi%10\n",
    "if result != 0:\n",
    "    string.append(data[result])\n",
    "    string.append('yi' )\n",
    "              \n",
    "\n",
    "result = wan//1000\n",
    "if result != 0:\n",
    "    string.append(data[result])\n",
    "    string.append('qian')\n",
    "    \n",
    "result = wan%1000//100\n",
    "if result != 0:\n",
    "    string.append(data[result])\n",
    "    string.append('bai')\n",
    "    \n",
    "result = wan%100//10\n",
    "if result != 0:\n",
    "    string.append(data[result])\n",
    "    string.append('shi')\n",
    "\n",
    "result = wan%10\n",
    "if result != 0:  \n",
    "    string.append(data[wan%10])\n",
    "    string.append('wan')\n",
    "\n",
    "if qian != 0:\n",
    "    string.append(data[qian])\n",
    "    string.append('qian')\n",
    "\n",
    "if bai != 0:\n",
    "    string.append(data[bai])\n",
    "    string.append('bai')\n",
    "\n",
    "if shi != 0:\n",
    "    string.append(data[shi])\n",
    "    string.append('shi')\n",
    "\n",
    "string.append(data[ge])\n",
    "\n",
    "if string[-2] != 'shi':\n",
    "    string.insert(-1,'ling')\n",
    "    \n",
    "print(\" \".join(string))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e1aabea2",
   "metadata": {},
   "source": [
    "### !!! 试题 基础练习 完美的代价"
   ]
  },
  {
   "cell_type": "raw",
   "id": "0de15246",
   "metadata": {},
   "source": [
    "资源限制\n",
    "时间限制：1.0s 内存限制：512.0MB\n",
    "问题描述\n",
    "　　回文串，是一种特殊的字符串，它从左往右读和从右往左读是一样的。小龙龙认为回文串才是完美的。现在给你一个串，它不一定是回文的，请你计算最少的交换次数使得该串变成一个完美的回文串。\n",
    "　　交换的定义是：交换两个相邻的字符\n",
    "　　例如mamad\n",
    "　　第一次交换 ad : mamda\n",
    "　　第二次交换 md : madma\n",
    "　　第三次交换 ma : madam (回文！完美！)\n",
    "输入格式\n",
    "　　第一行是一个整数N，表示接下来的字符串的长度(N <= 8000)\n",
    "　　第二行是一个字符串，长度为N.只包含小写字母\n",
    "输出格式\n",
    "　　如果可能，输出最少的交换次数。\n",
    "　　否则输出Impossible\n",
    "样例输入\n",
    "5\n",
    "mamad\n",
    "样例输出\n",
    "3"
   ]
  },
  {
   "cell_type": "raw",
   "id": "221a9d32",
   "metadata": {},
   "source": [
    "两种情况：\n",
    "1.impossible的情况：如果有一个字符出现的次数是奇数次数，而且n是偶数，那么不可能构成回文。\n",
    "如果n是奇数，但是已经有一个字符出现的次数是奇数次数了，那么如果又有一个字符是奇数次数，就不可能构成回文。\n",
    "2.如果n是奇数，计算中间那个字符交换的次数的时候，不需要模拟把这个数移动到中间去，因为移动到中间的话假设有一对数都在左边或者都在右边。\n",
    "那么交换成回文的时候就要经过中间，就会每次把cnt多加了1，而这个1是没有必要的，因为可以所有的回文移动完了之后再把这个独立的奇数移动过去，\n",
    "才能保证交换次数最少"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9ff8d6b6",
   "metadata": {},
   "outputs": [],
   "source": [
    "def is_pal(n, s):\n",
    "    temp = set()\n",
    "    if n % 2 == 0:\n",
    "        for i in range(26):\n",
    "            if s.count(chr(ord('a') + i)) % 2 != 0:\n",
    "                print('Impossible') # 如果字符串字符为偶数,但是存在不成对字符\n",
    "                return False\n",
    "        else:\n",
    "            return True\n",
    "    else:\n",
    "        for i in range(26):\n",
    "            if s.count(chr(ord('a') + i)) % 2 != 0:\n",
    "                temp.add(chr(ord('a') + i))\n",
    "            if len(temp) > 1:\n",
    "                print('Impossible')  # 如果字符串字符为奇数,但是存在不成对字符超过一个\n",
    "                return False\n",
    "        else:\n",
    "            return True\n",
    "\n",
    "def count_step(n, s, s1):\n",
    "    global ans\n",
    "    for i in range(n // 2):\n",
    "        if s[i:].count(s[i]) != 1:\n",
    "            temp = s1[:n - i].index(s[i])\n",
    "            s1.pop(temp)\n",
    "            ans += temp\n",
    "            s = s1[::-1]\n",
    "        else:\n",
    "            ans += n // 2 - i\n",
    "            s[i] = None # 将此奇数移动到中间后清除\n",
    "            s1 = s[::-1]\n",
    "    return ans\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    n = int(input()) # 字符串的长度\n",
    "    s = list(input()) # 输入字符串\n",
    "    s1 = s[::-1]\n",
    "    ans = 0\n",
    "\n",
    "    if is_pal(n, s):    # 如果是回文数 计算挪动的步数\n",
    "        print(count_step(n, s, s1))\n",
    "            "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a567cd87",
   "metadata": {},
   "source": [
    "### 试题 基础练习 矩形面积交"
   ]
  },
  {
   "cell_type": "raw",
   "id": "0ff9240b",
   "metadata": {},
   "source": [
    "题目：\n",
    "问题描述\n",
    "　　平面上有两个矩形，它们的边平行于直角坐标系的X轴或Y轴。对于每个矩形，我们给出它的一对相对顶点的坐标，请你编程算出两个矩形的交的面积。\n",
    "输入格式\n",
    "　　输入仅包含两行，每行描述一个矩形。\n",
    "　　在每行中，给出矩形的一对相对顶点的坐标，每个点的坐标都用两个绝对值不超过10^7的实数表示。\n",
    "输出格式\n",
    "　　输出仅包含一个实数，为交的面积，保留到小数后两位。\n",
    "样例输入\n",
    "1 1 3 3\n",
    "2 2 4 4\n",
    "样例输出\n",
    "1.00"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "22647892",
   "metadata": {},
   "outputs": [],
   "source": [
    "polts_1 = list(map(int,input().split()))\n",
    "polts_2 = list(map(int,input().split()))\n",
    "\n",
    "\n",
    "if max(polts_1) < min(polts_2) or min(polts_1) > max(polts_2):\n",
    "    print(0)\n",
    "\n",
    "elif min(polts_1) >= min(polts_2) and max(polts_1) <= max(polts_2):\n",
    "    \n",
    "    print(pow(max(polts_1) - min(polts_1),2))\n",
    "    \n",
    "elif min(polts_2) >= min(polts_1) and max(polts_2) <= max(polts_1):\n",
    "    \n",
    "    print(pow(max(polts_2) - min(polts_2),2))\n",
    "\n",
    "else:\n",
    "    \n",
    "    print('%.2f'%pow(max(polts_1) - min(polts_2),2))\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bde291dd",
   "metadata": {},
   "outputs": [],
   "source": [
    "list1 = list(map(float, input().split()))\n",
    "list2 = list(map(float, input().split()))\n",
    "\n",
    "x1 = max(min(list1[0], list1[2]), min(list2[0], list2[2]))\n",
    "x2 = min(max(list1[0], list1[2]), max(list2[0], list2[2]))\n",
    "y1 = max(min(list1[1], list1[3]), min(list2[1], list2[3]))\n",
    "y2 = min(max(list1[1], list1[3]), max(list2[1], list2[3]))\n",
    "\n",
    "if x1 < x2 and y1 < y2:\n",
    "    area = (x2 - x1)*(y2 - y1)\n",
    "    print('%.2f' % area)\n",
    "else:\n",
    "    print('%.2f' % 0.00)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "01867302",
   "metadata": {},
   "source": [
    "### !!! 试题 基础练习 矩阵乘法"
   ]
  },
  {
   "cell_type": "raw",
   "id": "ea9904e2",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　给定一个N阶矩阵A，输出A的M次幂（M是非负整数）\n",
    "　　例如：\n",
    "　　A =\n",
    "　　1 2\n",
    "　　3 4\n",
    "　　A的2次幂\n",
    "　　7 10\n",
    "　　15 22\n",
    "输入格式\n",
    "　　第一行是一个正整数N、M（1<=N<=30, 0<=M<=5），表示矩阵A的阶数和要求的幂数\n",
    "　　接下来N行，每行N个绝对值不超过10的非负整数，描述矩阵A的值\n",
    "输出格式\n",
    "　　输出共N行，每行N个整数，表示A的M次幂所对应的矩阵。相邻的数之间用一个空格隔开"
   ]
  },
  {
   "cell_type": "raw",
   "id": "e00fa40d",
   "metadata": {},
   "source": [
    "第一行乘以第一列=第一行的数乘第一列的数相加，得到新的arr[0][0]的数值\n",
    "第一行乘以第二列=第一行的数乘第二列的数相加，得到新的arr[0][1]的数值\n",
    "第一行乘以第三列=第一行的数乘第三列的数相加，得到新的arr[0][2]的数值"
   ]
  },
  {
   "cell_type": "raw",
   "id": "957740e8",
   "metadata": {},
   "source": [
    "列表的\"*\"操作\n",
    "\n",
    "在迭代对象前使用‘*’号，将变量中可迭代对象的元素拆解出来，变成若干独立的参数。\n",
    "\n",
    "_A = list(map(list, zip(*A))) # list转置\n",
    "\n",
    "zip() 函数用于将可迭代的对象作为参数，将对象中对应的元素打包成一个个元组，然后返回由这些元组组成的列表。\n",
    "\n",
    "zip 方法在 Python 2 和 Python 3 中的不同：在 Python 3.x 中为了减少内存，zip() 返回的是一个对象。如需展示列表，需手动 list() 转换。\n",
    "\n",
    "map() 会根据提供的函数对指定序列做映射.\n",
    "第一个参数 function 以参数序列中的每一个元素调用 function 函数，返回包含每次 function 函数返回值的新列表。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1dbfea87",
   "metadata": {},
   "outputs": [],
   "source": [
    "def do(A,M):\n",
    "     \n",
    "    for i in range(M-1):\n",
    "        _A = list(map(list, zip(*A)))\n",
    "        arr = list()\n",
    "        for row in A:\n",
    "            arr.append(list())\n",
    "            for column in _A:\n",
    "                result = 0\n",
    "                for value_row, value_column in zip(row, column):\n",
    "                    result += value_row * value_column\n",
    "\n",
    "                arr[-1].append(result)\n",
    "\n",
    "        A = arr\n",
    "    \n",
    "    return A\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    N,M = map(int,input().split())\n",
    "\n",
    "    A = [list(map(int,input().split())) for _ in range(N)]\n",
    "\n",
    "    A = do(A,M)\n",
    "    \n",
    "    for line in A:\n",
    "        \n",
    "        print(*line)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "98549826",
   "metadata": {},
   "source": [
    "### !!! 试题 基础练习 分解质因数"
   ]
  },
  {
   "cell_type": "raw",
   "id": "3b1b37a0",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　求出区间[a,b]中所有整数的质因数分解。\n",
    "输入格式\n",
    "　　输入两个整数a，b。\n",
    "输出格式\n",
    "　　每行输出一个数的分解，形如k=a1*a2*a3...(a1<=a2<=a3...，k也是从小到大的)(具体可看样例)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "1a975f24",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 10\n",
      "1=None\n",
      "2=2\n",
      "3=3\n",
      "4=2*2\n",
      "5=5\n",
      "6=2*3\n",
      "7=7\n",
      "8=2*2*2\n",
      "9=3*3\n",
      "10=2*5\n"
     ]
    }
   ],
   "source": [
    "def solve(tmp, n, result):\n",
    "    for i in range(2, n+1):\n",
    "        if n % i == 0:\n",
    "            tmp += str(i)\n",
    "            n = n // i\n",
    "            \n",
    "            if n == 1:\n",
    "                return tmp\n",
    "            \n",
    "            elif n in result.keys():\n",
    "                tmp += '*'\n",
    "                tmp += result[n]\n",
    "                return tmp\n",
    "            \n",
    "            else:\n",
    "                tmp += '*'\n",
    "                return solve(tmp, n, result)\n",
    "            \n",
    "        else:\n",
    "            continue\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    a, b = map(int, input().split()) # 输入两个整数\n",
    "    result = {}   # result存放值与其分解质因数的对应关系\n",
    "    # {3: '3', 4: '2*2', 5: '5', 6: '2*3', 7: '7', 8: '2*2*2', 9: '3*3', 10: '2*5'}\n",
    "    \n",
    "    for i in range(a, b+1):\n",
    "        tmp = ''  # 存放各个因数\n",
    "        result[i] = solve(tmp, i, result)\n",
    "    \n",
    "    # 输出\n",
    "    for k, v in result.items():\n",
    "        s = str(k)+ '=' + str(v)\n",
    "        print(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0e205c46",
   "metadata": {},
   "source": [
    "### 试题 基础练习 字符串对比"
   ]
  },
  {
   "cell_type": "raw",
   "id": "7f770243",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　给定两个仅由大写字母或小写字母组成的字符串(长度介于1到10之间)，它们之间的关系是以下4中情况之一：\n",
    "　　1：两个字符串长度不等。比如 Beijing 和 Hebei\n",
    "　　2：两个字符串不仅长度相等，而且相应位置上的字符完全一致(区分大小写)，比如 Beijing 和 Beijing\n",
    "　　3：两个字符串长度相等，相应位置上的字符仅在不区分大小写的前提下才能达到完全一致（也就是说，它并不满足情况2）。比如 beijing 和 BEIjing\n",
    "　　4：两个字符串长度相等，但是即使是不区分大小写也不能使这两个字符串一致。比如 Beijing 和 Nanjing\n",
    "　　编程判断输入的两个字符串之间的关系属于这四类中的哪一类，给出所属的类的编号。\n",
    "输入格式\n",
    "　　包括两行，每行都是一个字符串\n",
    "输出格式\n",
    "　　仅有一个数字，表明这两个字符串的关系编号\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c492c245",
   "metadata": {},
   "outputs": [],
   "source": [
    "A, B = input().split()\n",
    "\n",
    "if len(A) != len(B):\n",
    "    print(1)\n",
    "\n",
    "elif len(A) == len(B):\n",
    "    if A == B:\n",
    "        print(2)\n",
    "    \n",
    "    elif A.upper() == B.upper():\n",
    "        print(3)\n",
    "        \n",
    "    else:\n",
    "        print(4)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2132d815",
   "metadata": {},
   "source": [
    "### 试题 基础练习 时间转换"
   ]
  },
  {
   "cell_type": "raw",
   "id": "c183316a",
   "metadata": {},
   "source": [
    "问题描述\n",
    "　　给定一个以秒为单位的时间t，要求用“<H>:<M>:<S>”的格式来表示这个时间。<H>表示时间，<M>表示分钟，而<S>表示秒，它们都是整数且没有前导的“0”。例如，若t=0，则应输出是“0:0:0”；若t=3661，则输出“1:1:1”。\n",
    "输入格式\n",
    "　　输入只有一行，是一个整数t（0<=t<=86399）。\n",
    "输出格式\n",
    "　　输出只有一行，是以“<H>:<M>:<S>”的格式所表示的时间，不包括引号。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0639b02a",
   "metadata": {},
   "outputs": [],
   "source": [
    "time = int(input())\n",
    "hour = time // 3600\n",
    "minute = time % 3600 // 60\n",
    "second = time % 60\n",
    "\n",
    "print(hour,':',minute,':',second, sep='')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "lanqiaobei",
   "language": "python",
   "name": "lanqiaobei"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
